package LinkedList;

import java.util.List;

public class LinkedList {
    static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
        }
    }
    /* 在链表的节点 n0 之后插入节点 P */
    static void insert(ListNode n0,ListNode P){
        P.next  = n0.next;
        n0.next = P;
    }

    /*删除链表节点后的首个节点*/
    static void delete(ListNode n0){
        if (n0.next == null)return;
        n0.next = n0.next.next;
    }

    public static void main(String[] args) {
        //初始化链表
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        ListNode node5 = new ListNode(5);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;
        node5.next = null;
        ListNode node = node1;
        ListNode node6 = new ListNode(6);
        insert(node5,node6);
        delete(node1);
        while (node != null){
            System.out.println(node.val);
            node = node.next;
        }
    }
}
